package com.hnkywl.jip.dao;

import com.hnkywl.jip.utils.BankData;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-3-1
 * Time: 下午4:55
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class BankDao extends SimpleHibernateTemplate {
    public List searchBankMapping(Integer companyId) {
        String sql = "select a.bankid,a.name,b.compid,compname=dbo.gf_compid_fullname(a.compid),a.jiuqi_saving_code,a.jiuqi_loan_code,a.jiuqitype" +
                " from dbo.t_cw_bank a,dbo.t_sys_comp b where a.compid=b.compid and b.compid=? " +
                " and a.status=1";
        List<Object[]> result = createSQLQuery(sql, companyId).list();
        if (result != null && !result.isEmpty())
            return result;
        return null;
    }

    public void saveBankMapping(BankData bankData) {
//        String sql = "update dbo.t_cw_bank  set jiuqi_saving_code=:saving,jiuqi_loan_code=:loan,jiuqitype=:type where bankid=:bankId";
        String sql = "update dbo.t_cw_bank  set jiuqi_saving_code=:saving,jiuqi_loan_code=:loan where bankid=:bankId";
        SQLQuery query = createSQLQuery(sql);
        query.setInteger("bankId", bankData.getBankId());
        query.setString("saving", bankData.getSaving());
        query.setString("loan", bankData.getLoan());
//        query.setInteger("type", bankData.getType());
        query.executeUpdate();
    }

}
